﻿//-----------------------------------------------------------------
//
// @(#)$Id: ProgCategoryDetail.aspx.cs,v 1.0 2013/12/16 9:51:29 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/16 9:51:29 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_SystemTableAdapters;

public partial class UI_SysSet_ProgCategoryDetail : System.Web.UI.Page
{
    static string act = "";
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        ddw_subsysId.DataSource = new T_SubSysCategoryTableAdapter().GetData();
        ddw_subsysId.DataValueField = "SubSysId";
        ddw_subsysId.DataTextField = "SubSysName";
        ddw_subsysId.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //WebUtility.CheckRight();
        if (!IsPostBack)
        {
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        //this.fdno.ReadOnly = false;                       
                        break;
                    case "U":
                        string progid = Request.QueryString["id"];
                        T_ProgCategoryTableAdapter adapter = new T_ProgCategoryTableAdapter();
                        DataTable table = adapter.GetDataByProgId(progid);
                        DataRow r = table.Rows[0];
                        this.txt_progId.ReadOnly = true;
                        this.txt_progId.Text = r["progId"].ToString();
                        this.txt_progName.Text = r["progName"].ToString();
                        this.txt_progexec.Text = r["ProgExecName"].ToString();
                        this.txt_sortId.Text = r["sortId"].ToString();
                        this.ddw_subsysId.SelectedValue = r["SubSysId"].ToString();
                        this.txt_Mnote.Text = r["Mnote"].ToString();
                        break;
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        string userId = Session["UserId"].ToString();
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        T_ProgCategoryTableAdapter adpter = new T_ProgCategoryTableAdapter();
                        int val = adpter.Insert(
                            txt_progId.Text,
                            txt_progName.Text,
                            txt_progexec.Text,
                            ddw_subsysId.SelectedValue.ToString(),
                            Convert.ToInt32(txt_sortId.Text),
                            txt_Mnote.Text,
                            userId,
                            DateTime.Now,
                            "",
                            DateTime.Now);

                        if (val > 0)
                        {
                            Response.Write("<script>alert('新增成功!');window.location.href='ProgCategory.aspx'</script>");
                        }
                    }
                    break;
                case "U":
                    {

                        T_ProgCategoryTableAdapter adpter = new T_ProgCategoryTableAdapter();
                        int val = adpter.Update(
                            txt_progName.Text,
                            txt_progexec.Text,
                            ddw_subsysId.SelectedValue.ToString(),
                            Convert.ToInt32(txt_sortId.Text),
                            txt_Mnote.Text,
                            userId,
                            DateTime.Now,
                            "",
                            DateTime.Now,
                            txt_progId.Text);

                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='ProgCategory.aspx'</script>");
                        }
                    }
                    break;
            }
        }
    }
}
